
/**
 * Grid 组件
 * 
 */
define(function(require, exports, module) {
			require("../theme/default/css/grid.css")
			var Widget = require("core/widget/dist/widget");
			var grid_tpl = require("./grid.tpl");
			var handlebars = require("core/widget/dist/handlebars");
			
			/**
			 * 扩展handlebars
			 */
			handlebars.registerHelper("grid", function(context, options) {
						var ret = "";
						if (context.model) {
							var records = context.model.records;
							var columns = context.attrs.columns;
							for (var i = 0; i < records.length; i++) {
								ret += "<tr>";
								for (var j = 0; j < columns.length; j++) {
									ret += "<td>";
									var data = records[i];
									var colId = columns[j].key;
									ret += data[colId];
									ret += "</td>";  
								}
								ret += "</tr>";
							}
						}
						return ret;
					})

			var Grid = Widget.extend({
						template : grid_tpl,
						loadData : function() {
							var list = this;
							var url = this.get("url");
							$.ajax({
										type : 'POST',
										url : url,
										success : function(data) {
											list.setModel(data);
										},
										dataType : 'json'
									});
						},
						handlebars : handlebars
					});
			module.exports = Grid;
		});